<?php

Class Zhishidi_Bestsellers_Model_Settings {
    const XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH = "zhishidi_bestsellers_info/sidebar/";
    const XML_BEST_SELLERS_SETTINGS_PAGE_PATH = "zhishidi_bestsellers_info/page/";

    public function getLimitDate($days) {

        $product = array();
        $product['todaydate'] = date('Y-m-d H:i:s', time());
        $product['startdate'] = date('Y-m-d H:i:s', time() - 60 * 60 * 24 * $days);
        return $product;
    }

    public function getColumnCount($column = 3) {
        return Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_PAGE_PATH . 'column_count');
    }

    public function isEnabled() {
        return Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . 'sidebar_enable');
    }

    public function getPageTitle() {
        return Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_PAGE_PATH . 'page_title');
    }

    public function getSidebarTitle() {
        return Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . 'sidebar_title');
    }

    public function getCategoriesID($key) {
        if (empty($key))
            return array();
        $cat = Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . $key);
        $cat = explode(",", $cat);
        $cat = array_filter($cat);

        return $cat;
    }

    public function getSidebarCategoriesID() {
        return $this->getCategoriesID('sidebar_cat');
    }

    public function getPageCategoriesID() {
        return $this->getCategoriesID('page_cat');
    }

    public function getCategory($id) {
        $categoryId = $id;

        if (!$categoryId || !is_numeric($categoryId))
            $category = Mage::registry("current_category");
        else {
            $category = Mage::getModel("catalog/category")->load($categoryId);
            if (!$category->getId())
                $category = Mage::registry("current_category");
        }
        return $category;
    }

    public function getSidebarLimit() {
        $count = (int) Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . 'sidebar_count');
        if ($count <= 0)
            $count = 10;
        return $count;
    }

    public function getSidebarDaysLimit() {
        $count = (int) Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . 'sidebar_days');
        if ($count <= 0)
            $count = 30;
        return $count;
    }

    public function getPageDaysLimit() {
        $count = (int) Mage::getStoreConfig(self::XML_BEST_SELLERS_SETTINGS_SIDEBAR_PATH . 'page_days');
        if ($count <= 0)
            $count = 30;
        return $count;
    }

}



